/**
 * 
 */
package com.aptech.restrant.Bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import javax.servlet.jsp.tagext.TryCatchFinally;

import com.aptech.restrant.Model.*;
import com.aptech.restrant.Bean.*;

/**
 * 用户Bean类
 * @author Administrator
 *
 */
public class UserDataBean {
	
	private ResultSet rs = null;
	
	/**
	 * 添加一个用户
	 * @param user 用户实体
	 * @return 影响的行数
	 */
	public int addUser(UserBean user){
		int row = 0;
		try {
			String sql = "insert into tb_userInfo (userName, userPass, userMail, userRealName, userSex,tel,IDcard) values (?,?,?,?,?,?,?)";
			Object[] obj = new Object[]{user.getUserName(),user.getUserPass(),user.getUserMail(),user.getUserRealName(),user.getUserSex(),user.getTel(),user.getIDcard()};
			row = DBConnection.executeUpdate(sql,obj);		
		} catch (Exception e) {
			System.out.println("添加用户信息时出错！");
			e.printStackTrace();
		}
		return row;
	}
	
	/**
	 * 根据用户名查找一个用户Bean
	 * @param name 用户名
	 * @return 用户Bean
	 */
	public UserBean findUserByName(String name){
		UserBean user = null;
		String sql = "select * from tb_userInfo where userName = ?";
		String [] str = new String[]{name};
		try {
			rs = DBConnection.getResultSet(sql, str);
			if(rs.next()){
				user = new UserBean();
				user.setUserID(rs.getInt("userID"));
				user.setUserName(rs.getString("userName"));
				user.setUserPass(rs.getString("userPass"));
				user.setUserRealName(rs.getString("userRealName"));
				user.setUserSex(rs.getString("userSex"));
				user.setTel(rs.getString("tel"));
				user.setIDcard(rs.getString("IDcard"));
			}
		} catch (Exception e) {
			System.out.println("findUserByName方法时出错");
			e.printStackTrace();
		} finally {
			DBConnection.close_All(rs);
		}
		
		return user;
	}
}
